/*
 * Copyright 2010 Electronic Business Systems Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package gr.ebs.gssdroid.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class GssPreferences {
	private SharedPreferences _prefs = null;
    private Editor _editor = null;
    
    public GssPreferences(Context context) {
    	this._prefs = context.getSharedPreferences("PREFS_PRIVATE", Context.MODE_PRIVATE);
        this._editor = this._prefs.edit();
	}
    public boolean hasData(){
    	if(getUsername().equals("")||getPassword().equals(""))
    		return false;
    	return true;
    }
    
    public boolean hasSystemData(){
    	if(getLogin().equals("")||getToken().equals(""))
    		return false;
    	return true;
    }
    public String getUsername() {
        if (this._prefs == null) {
            return "";
        }

        return this._prefs.getString("username", "");
    }

    public String getPassword() {
        return this._prefs.getString("password", "");
    }

    public void setUsername(String newemail) {
        if (this._editor == null) {
            return;
        }

        this._editor.putString("username", newemail);
    }

    public void setPassword(String serverurl) {
        if (this._editor == null) {
            return;
        }
        this._editor.putString("password", serverurl);
    }
    
    public String getLogin() {
        if (this._prefs == null) {
            return "";
        }

        return this._prefs.getString("login", "");
    }

    public String getToken() {
        return this._prefs.getString("token", "");
    }

    public void setLogin(String newemail) {
        if (this._editor == null) {
            return;
        }

        this._editor.putString("login", newemail);
    }

    public void setToken(String serverurl) {
        if (this._editor == null) {
            return;
        }
        this._editor.putString("token", serverurl);
    }

    public void save() {
        if (this._editor == null) {
            return;
        }
        this._editor.commit();
    }
}
